package com.sfj.system.controller;

import com.kaka.starter.control.dto.ResultBean;
import com.sfj.system.dto.group.GroupAddDTO;
import com.sfj.system.dto.group.GroupQueryDTO;
import com.sfj.system.dto.group.GroupUpdDTO;
import com.sfj.system.entity.GroupEntity;
import com.sfj.system.service.group.GroupService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author kaka
 * @Date 2025/06/29
 */
@RestController
@RequestMapping("group")
@Api(tags = "用户群组管理")
public class GroupController {

    @Autowired
    private GroupService groupService;

    @PostMapping("/getGroupNameByIds")
    @ApiOperation(value = "根据ids获取组织名", notes = "根据ids获取组织名")
    public ResultBean getUserNameByIds(@RequestBody List<Integer> groupIds) {
        return ResultBean.succeed(groupService.getGroupNameByIds(groupIds));
    }

    @GetMapping("/getById")
    @ApiOperation("根据 ID 获取群组信息")
    public ResultBean getById(@RequestParam String groupId) {
        GroupEntity group = groupService.getById(groupId);
        return group == null ? ResultBean.fail("群组不存在") : ResultBean.succeed(group);
    }

    @PostMapping("/query")
    @ApiOperation(value = "获取所有群组列表", notes = "获取所有群组列表")
    public ResultBean queryGroupListByPage(@RequestBody GroupQueryDTO groupQueryDTO) {
        return ResultBean.succeed(groupService.queryGroupListByPage(groupQueryDTO));
    }

    @PostMapping("/list")
    @ApiOperation(value = "获取所有群组id,name列表", notes = "获取所有群组id,name列表")
    public ResultBean queryGroupList() {
        return ResultBean.succeed(groupService.queryGroupList());
    }

    @PostMapping("/taskList")
    @ApiOperation(value = "获取任务可选择的群组id,name列表", notes = "获取任务可选择的群组id,name列表")
    public ResultBean queryTaskGroupList() {
        return ResultBean.succeed(groupService.queryTaskGroupList());
    }


    @PostMapping("/add")
    @ApiOperation("新增群组")
    public ResultBean add(@RequestBody GroupAddDTO group) {
        groupService.add(group);
        return ResultBean.succeed();
    }

    @PostMapping("/update")
    @ApiOperation("更新群组")
    public ResultBean update(@RequestBody GroupUpdDTO group) {
        groupService.update(group);
        return ResultBean.succeed();
    }

    @PostMapping("/delete")
    @ApiOperation("删除群组")
    public ResultBean delete(@RequestBody Integer groupId) {
        groupService.delete(groupId);
        return ResultBean.succeed();
    }
}
